﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Fetion.Core
{
   /// <summary>
   /// Fetion.Core组件处理异常
   /// </summary>
    public class NetTcpException:Exception
    {
        /// <summary>
        /// 构建对象
        /// </summary>
        public NetTcpException()
        {
        }
        /// <summary>
        /// 构建指定错误信息的对象
        /// </summary>
        /// <param name="msg">错误信息</param>
        public NetTcpException(string msg)
            : base(msg)
        {
        }
        /// <summary>
        /// 错误号
        /// </summary>
        public int ErrorNumber
        {
            internal get;
            set;
        }
        /// <summary>
        /// 构建指定错误信息的对象
        /// </summary>
        /// <param name="innererr">内部异常</param>
        /// <param name="msg">错误信息</param>
        public NetTcpException(Exception innererr, string msg) : base(msg, innererr) { }
        internal const string MODULE_TAG = "<Modulus>{0}<Modulus/>";

        internal const string MSG_DATA_OVERFLOW = "The message is too long";
        internal const string MSG_READ_DATA_ERROR = "Cross-border access to data";
        internal const string MSG_ERROR_IPADDRESS = " IPAddress Error!";
        internal const string MSG_ERROR_TYPENOTFOUND = "{0} Type not found!";
        internal const string MSG_ERROR_OBJECT_LOADDATAERROR = "{0} load data error!";
        internal const int NetTcpError_DataOverflow = 10001;
        internal const int NetTcpError_ReadDataError = 10004;
        internal const int NetTcpError_IpAddress = 10006;
        internal static NetTcpException ObjectLoadError(string type, Exception innerexception)
        {
            return new NetTcpException(innerexception, string.Format(MSG_ERROR_OBJECT_LOADDATAERROR, type));
        }
        internal static NetTcpException StringEncodingError(Exception innerexception)
        {
            return new NetTcpException(innerexception, "string encoding error!");
        }
        internal static NetTcpException StringDecodingError(Exception innerexception)
        {
            return new NetTcpException(innerexception, "string decoding error!");
        }
        internal static NetTcpException NotInitialize()
        {
            return new NetTcpException("Fetion.Core component did not initialize!\r\nCall TcpUtil.Setup!");
        }
        internal static NetTcpException PacketAnyalysisNotInitialize()
        {
            return new NetTcpException("Fetion.Core Anyalysis  did not initialize!\r\nCall PacketAnalysis.Setup!");
        }
        internal static NetTcpException TypeNotFound(string name)
        {
            return new NetTcpException(string.Format(MSG_ERROR_TYPENOTFOUND, name));
        }
        internal static NetTcpException DataOverflow()
        {
            NetTcpException error = new NetTcpException(MSG_DATA_OVERFLOW);
            error.ErrorNumber = NetTcpError_DataOverflow;
            return error;
        }
        internal static NetTcpException ReadDataError(Exception innererror)
        {
            NetTcpException error = new NetTcpException(innererror,MSG_READ_DATA_ERROR);
            error.ErrorNumber = NetTcpError_ReadDataError;
            return error;
        }
        internal static NetTcpException IPAddressError()
        {
            NetTcpException error = new NetTcpException(MSG_ERROR_IPADDRESS);
            error.ErrorNumber = NetTcpError_IpAddress;
            return error;
        }
    }
   
   
}
